# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=openscad
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r5875.085167b
pkgrel=1
pkgdesc="The programmers solid 3D CAD modeller (mingw-w64)"
arch=('any')
license=("GPL2")
url="http://openscad.org/"
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-cgal"
         "${MINGW_PACKAGE_PREFIX}-opencsg"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-qscintilla"
         "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-gdb"
             "${MINGW_PACKAGE_PREFIX}-imagemagick"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "bison"
             "make"
             "git")
options=(!strip staticlibs !buildflags)
source=("${_realname}"::"git+https://github.com/openscad/openscad.git")
sha256sums=('SKIP')

pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  rm -f libraries/MCAD/*.py
}

build() {
  cd ${srcdir}/${_realname}
  BOOSTDIR=${MINGW_PREFIX} \
  CGALDIR=${MINGW_PREFIX} \
  EIGENDIR=${MINGW_PREFIX} \
  GLEWDIR=${MINGW_PREFIX} \
  OPENCSGDIR=${MINGW_PREFIX} \
  ${MINGW_PREFIX}/bin/qmake CONFIG+=release PREFIX="${pkgdir}${MINGW_PREFIX}"

  make -j1
  convert "icons/${_realname}.png" -resize 128x128\> "icons/${_realname}-128.png"
}

package() {
  cd ${srcdir}/${_realname}
  make INSTALL_ROOT= install
  install -Dm644 "icons/${_realname}.xml" "${pkgdir}${MINGW_PREFIX}/share/mime/packages/${_realname}.xml"
}
